<?php
require_once('config.php');

$username=$_GET['username'];
$telephone=$_GET['telephone'];
$password=$_GET['password'];

$sql="select count(*) from userinfo where username='$username'";

$result=mysqli_query($conn,$sql);

$data=mysqli_fetch_array($result);

// echo json_encode($data);

$obj=array();
if($data['0']>0){//用户已存在
    $obj['code']=0;
    $obj['msg']="用户已存在";
    $obj['data']=false;

}else{
    $sql="insert into userinfo(username,telephone,password) VALUES('$username','$telephone','$password')";
    mysqli_query($conn,$sql);
    $cont=mysqli_affected_rows($conn);

    if($cont>0){
        $obj['code']=1;
        $obj['msg']="用户注册成功";
        $obj['data']=true;
    }

}
echo json_encode($obj);





// $arr=array();
// while($data=mysqli_fetch_array($result)){
//     $obj=array();
//     $obj['username']=$data['username'];
//     $obj['password']=$data['password'];
//     $obj['telephone']=$data['telephone'];
//     $obj['id']=$data['id'];
//     $arr[]=$obj;

// }

// echo json_encode($arr);